package edu.njfu.intentdemo

import android.app.Activity
import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.Button
import android.widget.TextView

class SecondActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_second)
        val textView2=findViewById<TextView>(R.id.textView2)
        val textView3=findViewById<TextView>(R.id.textView3)
        textView2.text=intent.getStringExtra("name")
        textView3.text=intent.getStringExtra("password")
        //跳转到第3个activity
        val button2=findViewById<Button>(R.id.button2)
        //把值传递给第一个activity
        val button3=findViewById<Button>(R.id.button3)
        button3.setOnClickListener {
            val intent = Intent();
            intent.putExtra("msg","用户名密码正确")
            setResult(Activity.RESULT_OK,intent)
            finish()
        }

    }

    override fun onBackPressed() {
        //super.onBackPressed()
        val intent = Intent();
        intent.putExtra("msg","用户名密码正确")
        setResult(Activity.RESULT_OK,intent)
        finish()
    }
}